#include <iostream>
#include <list>

#include <QtGui>

#include "invader_label.h"
#include "invader_font.h"

InvaderLabel::InvaderLabel (const QString &label, QWidget *parent)
  : QFrame (parent)
{
  _layout = new QHBoxLayout (this);
  _layout->setSizeConstraint (QLayout::SetFixedSize);

  setText (label);

  setLayout (_layout);
}

void InvaderLabel::setText (const QString &label)
{
  QLayoutItem *child;

  while ((child = _layout->takeAt (0)) != 0) {
    child->widget ()->deleteLater ();
    delete child;
  }

  QString::const_iterator beg = label.constBegin ();
  QString::const_iterator end = label.constEnd ();

  QLabel *l;
  for (; beg != end; ++beg) {
    l = new QLabel (this);
    l->setPixmap (InvaderFont::instance ()[*beg]);
    _glyphs.push_back (l);
    
    _layout->addWidget (l);
  }
}
